#include "FibHeap.hpp"
#include <ctime>

int input_num[500];
int output[50];
time_t rtime[5];


void run(){

    for (size_t i = 0; i < 5; i++)
    {
        rtime[i] = 0;
    }
    

    for (size_t i = 0; i < 1001; i++)
    {
        FibHeap_Node x;
        x.key = 0;
        x.left = nullptr;
        x.right = nullptr;
        x.p = nullptr;
        x.child = nullptr;
        x.degree = 0;
        x.mark = false;
        node_array[i] = x;
    }

    FibHeap H1;
    FibHeap H2;
    FibHeap H3;
    FibHeap H4;
    for (size_t i = 0; i < 50; i++)
    {
        H1.INSERT(input_num[i]);
    }
    for (size_t i = 50; i < 150; i++)
    {
        H2.INSERT(input_num[i]);
    }
    for (size_t i = 150; i < 300; i++)
    {
        H3.INSERT(input_num[i]);
    }
    for (size_t i = 300; i < 500; i++)
    {
        H4.INSERT(input_num[i]);
    }

    int i;

    /*
    INSERT(H1,249);INSERT(H1,830);MINIMUM(H1);DELETE(H1,127);DELETE(H1,141); MINIMUM(H1);
    DECREASE-KEY(H1,75,61);DECREASE-KEY(H1,198,169); EXTRACT-MIN(H1);EXTRACT-MIN(H1);
     */
    rtime[0] = clock();
    output[i++] = H1.INSERT(249);
    output[i++] = H1.INSERT(830);
    output[i++] = H1.MINIMUN();
    output[i++] = H1.DELETE(127);
    output[i++] = H1.DELETE(141);
    output[i++] = H1.MINIMUN();
    output[i++] = H1.DECREASE_KEY(75, 64);
    output[i++] = H1.DECREASE_KEY(198, 169);
    output[i++] = H1.EXTRACT_MIN();
    output[i++] = H1.EXTRACT_MIN();
    rtime[0] = clock() - rtime[0];

    /*
    INSERT(H2,816); MINIMUM(H2); INSERT(H2,345); EXTRACT-MIN(H2);DELETE(H2,504);DELETE(H2,203);
    DECREASE-KEY(H2,296,87);DECREASE-KEY(H2,278,258);MINIMUM(H2);EXTRACT-MIN(H2);
    */
   rtime[1] = clock();
    output[i++] = H2.INSERT(816);
    output[i++] = H2.MINIMUN();
    output[i++] = H2.INSERT(345);
    output[i++] = H2.EXTRACT_MIN();
    output[i++] = H2.DELETE(504);
    output[i++] = H2.DELETE(203);
    output[i++] = H2.DECREASE_KEY(296, 87);
    output[i++] = H2.DECREASE_KEY(278, 258);
    output[i++] = H2.MINIMUN();
    output[i++] = H2.EXTRACT_MIN();
    rtime[1] = clock() - rtime[1];

    /*
    EXTRACT-MIN(H3); MINIMUM(H3);INSERT(H3,262); EXTRACT-MIN(H3);INSERT(H3,832);MINIMUM(H3);
    DELETE(H3,134);DELETE(H3,177);DECREASE-KEY(H3,617,360);DECREASE-KEY(H3,889,353); 
    */
   rtime[2] = clock();
    output[i++] = H3.EXTRACT_MIN();
    output[i++] = H3.MINIMUN();
    output[i++] = H3.INSERT(262);
    output[i++] = H3.EXTRACT_MIN();
    output[i++] = H3.INSERT(832);
    output[i++] = H3.MINIMUN();
    output[i++] = H3.DELETE(134);
    output[i++] = H3.DELETE(177);
    output[i++] = H3.DECREASE_KEY(617, 360);
    output[i++] = H3.DECREASE_KEY(889, 353);
    rtime[2] = clock() - rtime[2];

    /*
    MINIMUM(H4); DELETE(H4,708); INSERT(H4,281);INSERT(H4,347);MINIMUM(H4);DELETE(H4,415); 
    EXTRACT-MIN(H4); DECREASE-KEY(H4,620,354);DECREASE-KEY(H4,410,80); EXTRACT-MIN(H4);
    */
   rtime[3] = clock();
    output[i++] = H4.MINIMUN();
    output[i++] = H4.DELETE(708);
    output[i++] = H4.INSERT(281);
    output[i++] = H4.INSERT(347);
    output[i++] = H4.MINIMUN();
    output[i++] = H4.DELETE(415);
    output[i++] = H4.EXTRACT_MIN();
    output[i++] = H4.DECREASE_KEY(620, 354);
    output[i++] = H4.DECREASE_KEY(410, 80);
    output[i++] = H4.EXTRACT_MIN();
    rtime[3] = clock() - rtime[3];

    //union
    auto H5 = UNION(H1, H2);
    H5 = UNION(H5, H3);
    H5 = UNION(H5, H4);

    /*
    EXTRACT-MIN(H5); MINIMUM(H5); DELETE(H5,800); INSERT(H5,267);INSERT(H5,351); EXTRACT-MIN(H5); 
    DECREASE-KEY(H5,478,444);DECREASE-KEY(H5,559,456);MINIMUM(H5); DELETE(H5,929);
    */
   rtime[4] = clock();
    output[i++] = H5.EXTRACT_MIN();
    output[i++] = H5.MINIMUN();
    output[i++] = H5.DELETE(800);
    output[i++] = H5.INSERT(267);
    output[i++] = H5.INSERT(351);
    output[i++] = H5.EXTRACT_MIN();
    output[i++] = H5.DECREASE_KEY(478, 444);
    output[i++] = H5.DECREASE_KEY(559, 456);
    output[i++] = H5.MINIMUN();
    output[i++] = H5.DELETE(929);
    rtime[4] = clock() - rtime[4];
}

int main(){
    for (size_t i = 0; i < 500; i++)
    {
        scanf("%d", &input_num[i]);
    }

    run();
    for (size_t i = 0; i < 50; i++)
    {
        if (i % 10 != 0)
        {
            cout << ',';
        }
        cout << output[i];
        if (i % 10 == 9)
        {
            cout << endl;
        }
    }

    for (size_t i = 0; i < 5; i++)
    {
        cout << rtime[i] << '\t';
    }
    
    
}